home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / keyb / dblcap10.zip / DBLCAP.ASM next >
Assembly Source File  |  1994-01-23  |  7KB  |  184 lines

  1. ; DBLCAP v1.0 ∙ CapsLock Fixer
  2. ; Copyright (c) 1993 by Dale Nurden
  3.  
  4. ; This program is a TSR which watches the keyboard for presses of the
  5. ; CapsLock key, and works like this:
  6. ;
  7. ; ∙ One press of CapsLock has no effect.
  8. ; ∙ Two presses within a certain time (0.3 seconds) of each other work just
  9. ;   like the normal CapsLock function.
  10. ;
  11. ; In addition, pressing Ctrl-Alt-Backspace at any time will empty the
  12. ; keyboard buffer. This is useful if you type commands in advance and then
  13. ; change your mind.
  14.  
  15. ; This source is released as is. The author makes no guarantees about its
  16. ; reliability, assemble-ility, or anything else. You may use portions of
  17. ; this source for your own purposes in shareware/freeware products, but I
  18. ; would appreciate it if you tell me about it, just so I know. I don't
  19. ; want anything in return, just to know that my work is useful to someone.
  20. ; A small note of credit to me would also be nice.
  21. ;
  22. ; Assembly information:
  23. ; Assembler: Turbo Assembler v3.1  [TASM DBLCAP.ASM /ZN /ML]
  24. ;    Linker: Turbo Linker v3.01    [TLINK DBLCAP.OBJ /T]
  25.  
  26.  
  27. ;=============================================================================
  28.  
  29.               .model small
  30.               .code
  31.  
  32. CAPSLOCKmake  equ  3Ah                  ;CapsLock key make code
  33. CAPSLOCKbreak equ  0BAh                 ;CapsLock key break code
  34. BACKSPACEmake equ  0Eh                  ;Backspace key make code
  35. BACKSPACEmask equ  00001100b            ;Ctrl-Alt shift mask
  36.  
  37. TIMEHI        equ  0004h                ;TIMEHI:TIMELO = maximum time (in microseconds)
  38. TIMELO        equ  93E0h                ;between presses of CapsLock for it to trigger
  39.                                         ;0004:93E0 = 0.3 seconds (300 000 microseconds)
  40.  
  41. SET           macro  byte,bit           ;Sets the specified bit in 'byte' to 1
  42.               or   byte,(bit)
  43.               endm
  44. CLR           macro  byte,bit           ;Clears the specified bit in 'byte' to 0
  45.               and  byte,not (bit)
  46.               endm
  47.  
  48.  
  49. ;=============================================================================
  50. ; RESIDENT SECTION
  51.  
  52.               org  2Ch                  ;Environment starts here
  53. Environment:
  54.  
  55.               org  80h                  ;Command line parameters start here
  56. CommandLine:
  57.  
  58.               org  100h                 ;Program data and code starts here
  59. DCAP:
  60.  
  61.               jmp  Install              ;Go and install the TSR
  62.  
  63. ;-----------------------------------------------------------------------------
  64. ; RESIDENT DATA
  65.  
  66. OldInt9       dd   ?                    ;Old Int 9 handler vector
  67.  
  68. flags         db   10000001b            ;This byte is used for keeping various flags
  69. MAKE          equ  00000001b            ;CapsLock has been pressed once
  70. TIMER         equ  10000000b            ;Timer timeout flag
  71.  
  72.  
  73. ;-----------------------------------------------------------------------------
  74. ; RESIDENT CODE
  75.  
  76. Int9:         push ax
  77.               in   al,60h               ;Get the keypress scan code
  78.               cmp  al,CAPSLOCKmake      ;Is it CapsLock make code?
  79.               je   int9_2
  80.               cmp  al,CAPSLOCKbreak     ;Is it CapsLock break code?
  81.               je   int9_5
  82.               cmp  al,BACKSPACEmake     ;Is it Backspace?
  83.               je   int9_6
  84.  
  85. int9_1:       pop  ax
  86.               jmp  cs:OldInt9           ;Pass keypress on to ISR chain
  87.  
  88.               ;CapsLock make code received
  89. int9_2:       test cs:flags,TIMER       ;Check timer flag for timeout
  90.               jnz  int9_3               ;Set, so this is a first press of CapsLock
  91.  
  92.               SET  cs:flags,TIMER       ;Otherwise reset the timer flag
  93.               jmp  int9_1               ;And pass on the keystroke
  94.  
  95. int9_3:       SET  cs:flags,MAKE        ;Indicate the first keypress
  96.  
  97. int9_4:       mov  al,20h               ;Acknowledge keyboard interrupt
  98.               out  20h,al               ; to kill the keypress
  99.               pop  ax
  100.               iret                      ;Then end the ISR
  101.  
  102.               ;CapsLock break code received
  103. int9_5:       test cs:flags,MAKE        ;Has a make code been seen before?
  104.               jz   int9_1               ;No, so pass it on
  105.  
  106.               CLR  cs:flags,<MAKE or TIMER>  ;Clear the flags
  107.  
  108.               push ax
  109.               push bx
  110.               push cx
  111.               push dx
  112.               push es
  113.  
  114.               push cs
  115.               pop  es
  116.               mov  bx,offset flags
  117.               mov  cx,TIMEHI            ;Event wait will set the
  118.               mov  dx,TIMELO            ; flag after a certain time
  119.               mov  ax,8300h
  120.               int  15h                  ;Start the event wait
  121.  
  122.               pop  es
  123.               pop  dx
  124.               pop  cx
  125.               pop  bx
  126.               pop  ax
  127.  
  128.               jmp  int9_4               ;Kill the keypress
  129.  
  130.               ;Backspace make code received
  131. int9_6:       mov  ah,12h
  132.               int  16h                  ;Get keyboard shift status
  133.               and  al,00001111b         ;And only look at bits 0-3
  134.               cmp  al,BACKSPACEmask     ;Is it our shift mask?
  135.               jne  int9_1               ;No, so pass it on
  136.  
  137.               ;Ctrl-Alt-Backspace received
  138. int9_7:       mov  ah,11h               ;Test keyboard buffer
  139.               int  16h                  ;Is there a key waiting?
  140.               jz   int9_4               ;No, so stop now and kill the hotkey
  141.               mov  ah,10h               ;Otherwise, remove it from the buffer
  142.               int  16h
  143.               jmp  int9_7               ;Now check for another key
  144.  
  145.  
  146.  
  147. EndTSR:
  148.  
  149.  
  150. ;=============================================================================
  151. ; NON_RESIDENT SECTION
  152. ; RESIDENT DATA
  153.  
  154. msg_header    db   13,10,"DBLCAP v1.0 ∙ CapsLock Fixer",13,10
  155.               db   "              Copyright (c) 1994 by Dale Nurden",13,10,10
  156.               db   "Press CAPSLOCK twice for it to be effective.",13,10
  157.               db   "Press CTRL-ALT-BACKSPACE at any time to clear the keyboard buffer.",13,10,'$'
  158.  
  159. ;-----------------------------------------------------------------------------
  160. ; NON-RESIDENT CODE
  161.  
  162. Install:      mov  ax,3509h
  163.               int  21h                  ;Get the old Int 9 handler vector
  164.               mov  word ptr OldInt9[0],bx
  165.               mov  word ptr OldInt9[2],es  ;And save it
  166.  
  167.               mov  ax,2509h
  168.               mov  dx,offset Int9
  169.               int  21h                  ;Now install the new handler
  170.  
  171.               mov  ah,9
  172.               mov  dx,offset msg_header
  173.               int  21h                  ;Print the header message
  174.  
  175.               mov  ax,word ptr [Environment]
  176.               mov  es,ax
  177.               mov  ah,49h
  178.               int  21h                  ;Release the environment
  179.  
  180.               mov  dx,offset EndTSR
  181.               int  27h                  ;Go TSR and exit
  182.  
  183.               end  DCAP
  184.